<include file="Public/min-header" />
<section class="wrapper">
   
    <div class="row">
        <div class="col-xs-12"> 
        <!-- Main content -->      
            <div class="panel">
                <div class="panel-heading"><i class="icon-cog"></i> 权限资源管理
                    <div class="pull-right">
                        <button type="button" id="pzReturn-btn" class="btn btn-default btn-xs" onclick="javascript:window.history.back();return false;"><i class="icon-reply"></i>返回</button>                       
                    </div>
                </div>
                <div class="panel-body">   
                    <!--表单数据-->
                    <form method="post" id="adminHandle" action="">                    
                        <!--通用信息-->
                    <div class="tab-content">                 	  
                        <div class="tab-pane active" id="tab_tongyong">                                                       
                                <div class="form-group">                                        
                                    <label class="col-xs-2 control-label">权限资源名称</label>
                                    <div class="col-xs-10">
                                        <input type="text" class="form-control" name="name" value="{$info.name}" />   
                                    </div>                                                                                       
                                </div>
                                <div class="form-group">                                        
                                    <label class="col-xs-2 control-label">所属分组</label>
                                    <div class="col-xs-10">
                                        <select name="group" class="form-control">
                                            <foreach name="group" item="vo" key="key">
                                                <option value="{$key}" <if condition="$info[group] eq $key">selected</if>>{$vo}</option>
                                            </foreach>
                                        </select>
                                        <span class="caret"></span>  
                                    </div>                                                                                       
                                </div>
                                <div class="form-group">                                                                
                                    <label class="col-xs-2 control-label">添加权限码</label>                                  
                                    <div  class="col-xs-3">
                                        <select id="controller" class="form-control" onchange="get_act_list(this)">
                                            <option value="">选择控制器</option>
                                            <foreach name="planList" item="vo">
                                               <option value="{$vo}">{$vo}</option>
                                            </foreach>           
                                        </select>
                                        <span class="caret"></span>  
                                    </div>
                                    <label class="col-xs-1 control-label">@</label>
                                    <div class="col-xs-3">
                                        <select class="form-control" id="act_list">                                                            
                                        </select>
                                        <span class="caret"></span>
                                    </div>
                                    <div class="col-xs-3"><input type="button" value="添加" onclick="add_right()" class="btn btn-primary"></div>    	                                  
                                </div>                                                                                          
                                		<table class="table table-bordered table-hover">
                                			 <thead><tr><th style="width:80%">权限码</th><th>操作</th></tr></thead>
                                			 <tbody id="rightList">
                                			 	<foreach name="info[right]" item="vo">
                                			 	<tr><td><input name="right[]" type="text" value="{$vo}" class="form-control" style="width:400px;"></td>
                                			 	<td><a href="javascript:;" onclick="$(this).parent().parent().remove();">删除</a></td></tr>
                                			 	</foreach>
                                			 </tbody>
                                		</table>                                                               		
                                <div class="pull-right">
                                    <input type="hidden" name="id" value="{$info.id}" />
                                    <input class="btn btn-submit" type="button" onclick="adsubmit()" value="保存" />
                                </div>                                	                                                                                        
                        </div>                           
                    </div>              
			    	</form><!--表单数据-->
                </div>     
            </div>
        </div>
    </div>   
</section>
<script>
function adsubmit(){
	if($('input[name=name]').val() == ''){
		layer.msg('权限名称不能为空！', {icon: 2,time: 1000});
		return false;
	}
	
	if($('input[name="right[]"').val() == ''){
		layer.msg('权限码不能为空！', {icon: 2,time: 1000});
		return false;
	}

	$('#adminHandle').submit();
}

function add_right(){
	var a = [];
	$('#rightList .form-control').each(function(i,o){
		if($(o).val() != ''){
			a.push($(o).val());
		}
	})
	var ncode = $('#controller').val();
	if(ncode !== ''){
		var temp = ncode+'@'+ $('#act_list').val();
		if($.inArray(temp,a) != -1){
			layer.msg('此权限码已经添加！', {icon: 2,time: 1000});
			return false;
		}
	}
	var strtr = '<tr>';
	if(ncode!= ''){
		strtr += '<td><input type="text" name="right[]" value="'+ncode+'@'+ $('#act_list').val()+'" class="form-control" style="width:400px;"></td>';
	}else{
		strtr += '<td><input type="text" name="right[]" value="" class="form-control" style="width:400px;"></td>';
	}		
	strtr += '<td><a href="javascript:;" onclick="$(this).parent().parent().remove();">删除</a></td>';
	$('#rightList').append(strtr);	
}

function get_act_list(obj){
	$.ajax({
		url: "{:U('System/ajax_get_action')}",
		type:'post',
		data: {'controller':$(obj).val()},
		dataType:'html',
		success:function(res){
			$('#act_list').empty().append(res);
		}
	});
}
</script>
</body>
</html>